package bounce;

import junit.framework.TestCase;

/**
 * Test cases to test NestingShape
 * 
 * @author Ken Neth Yeoh
 *
 */

public class TestNestingShape extends TestCase {
	private MockPainter painter;
	
	public void setUp() {
		painter = new MockPainter();
	}
	
	public void testTwoChildrenBounce() {
		RectangleTextShape text = new RectangleTextShape(10, 50, -15, 5, 80, 40, "hello world");
		RectangleShape rectangle = new RectangleShape(10, 50, -15, 15, 10, 10);
		NestingShape nest = new NestingShape(100, 100, 1, 1, 300, 300);
		nest.add(text);
		nest.add(rectangle);
		nest.paint(painter);
		nest.move(1000, 1000);
		nest.paint(painter);
		nest.move(1000, 1000);
		nest.paint(painter);
		nest.move(1000, 1000);
		assertEquals("(rectangle 110,150,80,40)(draw text hello world)(rectangle 110,150,10,10)(rectangle 101,156,80,40)(draw text hello world)(rectangle 101,166,10,10)(rectangle 117,162,80,40)(draw text hello world)(rectangle 117,182,10,10)", painter.toString());
	}
	
	public void testNestWithinNest() {
		RectangleTextShape text = new RectangleTextShape(10, 50, -15, 5, 80, 40, "hello world");
		RectangleShape rectangle = new RectangleShape(10, 50, -15, 15, 10, 10);
		NestingShape smallNest = new NestingShape(100, 100, 1, 1, 300, 300);
		smallNest.add(text);
		smallNest.add(rectangle);
		NestingShape largeNest = new NestingShape(100, 100, 1, 1, 700, 700);
		largeNest.add(smallNest);
		largeNest.paint(painter);
		largeNest.move(1000, 1000);
		largeNest.paint(painter);
		largeNest.move(1000, 1000);
		largeNest.paint(painter);
		largeNest.move(1000, 1000);
		assertEquals("(rectangle 210,250,80,40)(draw text hello world)(rectangle 210,250,10,10)(rectangle 202,257,80,40)(draw text hello world)(rectangle 202,267,10,10)(rectangle 219,264,80,40)(draw text hello world)(rectangle 219,284,10,10)", painter.toString());
	}
	
	public void testNestWithinBorder() {
		RectangleTextShape text = new RectangleTextShape(10, 50, -15, 5, 80, 40, "hello world");
		RectangleShape rectangle = new RectangleShape(10, 50, -15, 15, 10, 10);
		NestingShape smallNest = new NestingShape(100, 100, 1, 1, 300, 300);
		smallNest.add(text);
		smallNest.add(rectangle);
		NestingShape largeNest = new NestingShape(100, 100, 1, 1, 700, 700);
		largeNest.add(smallNest);
		BorderShape border = new BorderShape(largeNest);
		largeNest.paint(painter);
		largeNest.move(1000, 1000);
		border.paint(painter);
		border.move(1000, 1000);
		largeNest.paint(painter);
		largeNest.move(1000, 1000);
		border.paint(painter);
		border.move(1000, 1000);
		largeNest.paint(painter);
		largeNest.move(1000, 1000);
		border.paint(painter);
		border.move(1000, 1000);
		assertEquals("(rectangle 210,250,80,40)(draw text hello world)(rectangle 210,250,10,10)(rectangle 98,98,704,704)(rectangle 202,257,80,40)(draw text hello world)(rectangle 202,267,10,10)(rectangle 99,99,704,704)(rectangle 219,264,80,40)(draw text hello world)(rectangle 219,284,10,10)(rectangle 100,100,704,704)", painter.toString());
	}

}
